home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility2 / resgauge.zip / PROFILE.C < prev    next >
C/C++ Source or Header  |  1992-08-23  |  10KB  |  284 lines

  1. // ============================================================================
  2. // profile.c -- code for dealing with the configuration file.
  3. // ============================================================================
  4.  
  5.  
  6. #include <windows.h>
  7. #include "resgauge.h"
  8.  
  9.  
  10. // ============================================================================
  11. // > > > > > > > > > > > > > > >  code  begins  < < < < < < < < < < < < < < < <
  12. // ============================================================================
  13. // Retrieves the program configuration.
  14. // ----------------------------------------------------------------------------
  15. void
  16. FAR
  17. PASCAL
  18. GetConfig(void)
  19. {
  20.     char szApp[32];
  21.     char szKey[32];
  22.     char szProfile[32];
  23.     char szString[32];
  24.     char szTmp[32];
  25.     WORD wTmp;
  26.  
  27.     // load the application name and the profile name
  28.     LoadString(GhInst, IDS_APPLICATION, szApp, sizeof(szApp) - 1);
  29.     LoadString(GhInst, IDS_PROFILE, szProfile, sizeof(szProfile) - 1);
  30.  
  31.     // get the monitor mode
  32.     LoadString(GhInst, IDS_MONITOR, szKey, sizeof(szKey) - 1);
  33.     LoadString(GhInst, GcfgDef.wMonitor, szTmp, sizeof(szTmp) - 1);
  34.     GetPrivateProfileString(szApp,
  35.                             szKey,
  36.                             szTmp,
  37.                             szString,
  38.                             sizeof(szString),
  39.                             szProfile);
  40.     LoadString(GhInst, IDS_GDI, szTmp, sizeof(szTmp) - 1);
  41.     if ( lstrcmpi(szString, szTmp) == 0 )
  42.     {
  43.         GcfgCur.wMonitor = MONITOR_GDI;
  44.     }
  45.     else
  46.     {
  47.         LoadString(GhInst, IDS_USER, szTmp, sizeof(szTmp) - 1);
  48.         if ( lstrcmpi(szString, szTmp) == 0 )
  49.             GcfgCur.wMonitor = MONITOR_USER;
  50.         else
  51.             GcfgCur.wMonitor = MONITOR_BOTH;
  52.     }
  53.  
  54.     // get the alarm setting
  55.     LoadString(GhInst, IDS_ALARM_ENABLED, szKey, sizeof(szKey) - 1);
  56.     wTmp = GetPrivateProfileInt(szApp,
  57.                                 szKey,
  58.                                 GcfgDef.fAlarmEnabled,
  59.                                 szProfile);
  60.     if ( wTmp )
  61.         GcfgCur.fAlarmEnabled = TRUE;
  62.     else
  63.         GcfgCur.fAlarmEnabled = FALSE;
  64.  
  65.     // get the alarm type
  66.     LoadString(GhInst, IDS_ALARM_TYPE, szKey, sizeof(szKey) - 1);
  67.     LoadString(GhInst, GcfgDef.wAlarmType, szTmp, sizeof(szTmp) - 1);
  68.     GetPrivateProfileString(szApp,
  69.                             szKey,
  70.                             szTmp,
  71.                             szString,
  72.                             sizeof(szString),
  73.                             szProfile);
  74.     LoadString(GhInst, IDS_FLASH, szTmp, sizeof(szTmp) - 1);
  75.     if ( lstrcmpi(szString, szTmp) == 0 )
  76.         GcfgCur.wAlarmType = ALARM_FLASH;
  77.     else
  78.         GcfgCur.wAlarmType = ALARM_BEEP;
  79.  
  80.     // get the threshold value
  81.     LoadString(GhInst, IDS_THRESHOLD, szKey, sizeof(szKey) - 1);
  82.     wTmp = GetPrivateProfileInt(szApp, szKey, GcfgDef.wThreshold, szProfile);
  83.     GcfgCur.wThreshold = max(min(wTmp, 99), 1);
  84.  
  85.     // get the "keep on top" setting
  86.     LoadString(GhInst, IDS_KEEP_ON_TOP, szKey, sizeof(szKey) - 1);
  87.     wTmp = GetPrivateProfileInt(szApp, szKey, 0, szProfile);
  88.     if ( wTmp )
  89.         GcfgCur.fKeepOnTop = TRUE;
  90.     else
  91.         GcfgCur.fKeepOnTop = FALSE;
  92.  
  93.     // get the gauge color for GDI
  94.     LoadString(GhInst, IDS_COLOR_GDI, szKey, sizeof(szKey) - 1);
  95.     wsprintf(szTmp, "%lX", GcfgDef.dwColorGDI);
  96.     GetPrivateProfileString(szApp,
  97.                             szKey,
  98.                             szTmp,
  99.                             szString,
  100.                             sizeof(szString),
  101.                             szProfile);
  102.     if ( DecodeHexString(szString, &(GcfgCur.dwColorGDI)) != 0 )
  103.         GcfgCur.dwColorGDI = GcfgDef.dwColorGDI;
  104.  
  105.     // get the gauge color for User
  106.     LoadString(GhInst, IDS_COLOR_USER, szKey, sizeof(szKey) - 1);
  107.     wsprintf(szTmp, "%lX", GcfgDef.dwColorUser);
  108.     GetPrivateProfileString(szApp,
  109.                             szKey,
  110.                             szTmp,
  111.                             szString,
  112.                             sizeof(szString),
  113.                             szProfile);
  114.     if ( DecodeHexString(szString, &(GcfgCur.dwColorUser)) != 0 )
  115.         GcfgCur.dwColorUser = GcfgDef.dwColorUser;
  116.  
  117.     // get the gauge color for both
  118.     LoadString(GhInst, IDS_COLOR_BOTH, szKey, sizeof(szKey) - 1);
  119.     wsprintf(szTmp, "%lX", GcfgDef.dwColorBoth);
  120.     GetPrivateProfileString(szApp,
  121.                             szKey,
  122.                             szTmp,
  123.                             szString,
  124.                             sizeof(szString),
  125.                             szProfile);
  126.     if ( DecodeHexString(szString, &(GcfgCur.dwColorBoth)) != 0 )
  127.         GcfgCur.dwColorBoth = GcfgDef.dwColorBoth;
  128. } // GetConfig
  129.  
  130.  
  131. // ----------------------------------------------------------------------------
  132. // Saves the program configuration.
  133. // ----------------------------------------------------------------------------
  134. void
  135. FAR
  136. PASCAL
  137. SaveConfig(void)
  138. {
  139.     char szApp[32];
  140.     char szKey[32];
  141.     char szProfile[32];
  142.     char szString[32];
  143.     WORD wTmp;
  144.  
  145.     // load the application name and the profile name
  146.     LoadString(GhInst, IDS_APPLICATION, szApp, sizeof(szApp) - 1);
  147.     LoadString(GhInst, IDS_PROFILE, szProfile, sizeof(szProfile) - 1);
  148.  
  149.     // save the monitor mode
  150.     if ( GcfgCur.wMonitor == MONITOR_GDI )
  151.         wTmp = IDS_GDI;
  152.     else if ( GcfgCur.wMonitor == MONITOR_USER )
  153.         wTmp = IDS_USER;
  154.     else
  155.         wTmp = IDS_BOTH;
  156.     LoadString(GhInst, IDS_MONITOR, szKey, sizeof(szKey) - 1);
  157.     LoadString(GhInst, wTmp, szString, sizeof(szString) - 1);
  158.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  159.  
  160.     // save the alarm setting
  161.     if ( GcfgCur.fAlarmEnabled )
  162.         wTmp = IDS_TRUE;
  163.     else
  164.         wTmp = IDS_FALSE;
  165.     LoadString(GhInst, IDS_ALARM_ENABLED, szKey, sizeof(szKey) - 1);
  166.     LoadString(GhInst, wTmp, szString, sizeof(szString) - 1);
  167.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  168.  
  169.     // save the alarm type
  170.     if ( GcfgCur.wAlarmType == ALARM_FLASH )
  171.         wTmp = IDS_FLASH;
  172.     else
  173.         wTmp = IDS_BEEP;
  174.     LoadString(GhInst, IDS_ALARM_TYPE, szKey, sizeof(szKey) - 1);
  175.     LoadString(GhInst, wTmp, szString, sizeof(szString) - 1);
  176.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  177.  
  178.     // save the threshold value
  179.     wsprintf(szString, "%u", GcfgCur.wThreshold);
  180.     LoadString(GhInst, IDS_THRESHOLD, szKey, sizeof(szKey) - 1);
  181.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  182.  
  183.     // save the gauge color for GDI
  184.     LoadString(GhInst, IDS_COLOR_GDI, szKey, sizeof(szKey) - 1);
  185.     wsprintf(szString, "%lX", GcfgCur.dwColorGDI);
  186.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  187.  
  188.     // save the gauge color for User
  189.     LoadString(GhInst, IDS_COLOR_USER, szKey, sizeof(szKey) - 1);
  190.     wsprintf(szString, "%lX", GcfgCur.dwColorUser);
  191.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  192.  
  193.     // save the gauge color for both
  194.     LoadString(GhInst, IDS_COLOR_BOTH, szKey, sizeof(szKey) - 1);
  195.     wsprintf(szString, "%lX", GcfgCur.dwColorBoth);
  196.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  197. } // SaveConfig
  198.  
  199.  
  200. // ----------------------------------------------------------------------------
  201. // Saves the "keep on top" setting.
  202. // ----------------------------------------------------------------------------
  203. void
  204. FAR
  205. PASCAL
  206. SaveKeepOnTop(void)
  207. {
  208.     char szApp[32];
  209.     char szKey[32];
  210.     char szProfile[32];
  211.     char szString[32];
  212.     WORD wTmp;
  213.  
  214.     // load the application name and the profile name
  215.     LoadString(GhInst, IDS_APPLICATION, szApp, sizeof(szApp) - 1);
  216.     LoadString(GhInst, IDS_PROFILE, szProfile, sizeof(szProfile) - 1);
  217.  
  218.     // save the setting
  219.     if ( GcfgCur.fKeepOnTop )
  220.         wTmp = IDS_TRUE;
  221.     else
  222.         wTmp = IDS_FALSE;
  223.     LoadString(GhInst, IDS_KEEP_ON_TOP, szKey, sizeof(szKey) - 1);
  224.     LoadString(GhInst, wTmp, szString, sizeof(szString) - 1);
  225.     WritePrivateProfileString(szApp, szKey, szString, szProfile);
  226. } // SaveKeepOnTop
  227.  
  228.  
  229. // ----------------------------------------------------------------------------
  230. // Decodes a hex string into a DWORD in the caller.  The hex string can be no
  231. // longer than 8 characters, and an invalid character will abort decoding and
  232. // cause the function to return 1.
  233. // ----------------------------------------------------------------------------
  234. UINT
  235. FAR
  236. PASCAL
  237. DecodeHexString(
  238. LPSTR       lpstrValue,
  239. DWORD FAR * dwValue)
  240. {
  241.     char    chTmp;
  242.     int     nChars;
  243.     DWORD   dwTmp;
  244.     LPSTR   lpstrTmp;
  245.     UINT    uiReturn;
  246.  
  247.     // assume failure
  248.     uiReturn = 1;
  249.  
  250.     // initialize
  251.     lpstrTmp = lpstrValue;
  252.     nChars = 0;
  253.     dwTmp = 0;
  254.  
  255.     // traverse the string
  256.     while ( (*lpstrTmp) && (nChars < 8) )
  257.     {
  258.         chTmp = *lpstrTmp++;
  259.         ++nChars;
  260.         dwTmp <<= 4;
  261.         if ( (chTmp >= '0') && (chTmp <= '9') )
  262.             dwTmp += chTmp - '0';
  263.         else if ( (chTmp >= 'a') && (chTmp <= 'f') )
  264.             dwTmp += chTmp - 'a' + 10;
  265.         else if ( (chTmp >= 'A') && (chTmp <= 'F') )
  266.             dwTmp += chTmp - 'A' + 10;
  267.         else
  268.             break;
  269.     }
  270.  
  271.     if ((*lpstrTmp == 0) && (nChars <= 8) )
  272.     {
  273.         *dwValue = dwTmp;
  274.         uiReturn = 0;
  275.     }
  276.  
  277.     return(uiReturn);
  278. } // DecodeHexString
  279.  
  280.  
  281. // ================
  282. // end of profile.c
  283. // ================
  284.